//
//  CampusPreviewPicBroswerViewController.m
//  ShowYork
//
//  Created by hxh on 2021/3/31.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusPreviewPicBroswerViewController.h"

@interface CampusPreviewPicBroswerViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UIImageView *containImgView;
@property (nonatomic,strong)UIButton *backBtn;
@property (nonatomic,strong)UIImageView *backImgView;
@property (nonatomic,copy)NSString *url;
@end

@implementation CampusPreviewPicBroswerViewController

- (instancetype)initWithPreviewUrl:(NSString *)previewUrl{
    if (self = [super init]) {
        self.url = previewUrl;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.isHideNavBar = YES;
    
    [self setUI];
    
    // Do any additional setup after loading the view.
}

- (void)setUI{
    self.view.backgroundColor = [UIColor blackColor];
    
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.scrollView.contentSize = CGSizeMake(kScreenW, kScreenH);
    self.scrollView.delegate = self;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.minimumZoomScale = 1;
    self.scrollView.maximumZoomScale = 3;
    [self.view addSubview:self.scrollView];
   
    [self.scrollView setZoomScale:1.0];
    
    [self.view addSubview:self.scrollView];
      
    self.containImgView = [[UIImageView alloc]init];
    self.containImgView.userInteractionEnabled = YES;
    self.containImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.scrollView addSubview:self.containImgView];
    
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.view);
    }];
    
    [self.containImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.scrollView);
        make.size.mas_equalTo(CGSizeMake(kScreenW, kScreenH));
    }];
    
    [self.containImgView sd_setImageWithURL:[NSURL URLWithString:self.url]];
    
    self.backImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_back_normal_tag"]];
    [self.view addSubview:self.backImgView];
    [self.backImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(16);
        make.top.equalTo(self.view).offset(GK_STATUSBAR_HEIGHT + 12);
        
    }];
    self.backBtn = [[UIButton alloc]init];
    [self.backBtn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.backBtn];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.backImgView.mas_right).offset(16);
        make.top.equalTo(self.view).offset(GK_STATUSBAR_HEIGHT);
        make.bottom.equalTo(self.backImgView.mas_bottom).offset(8);
    }];
}

- (void)backMethod{
    [self.navigationController popViewControllerAnimated:YES];
    
}

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    
   for (UIView *v in scrollView.subviews){
       return v;
    }
    return nil;
}

@end
